package s17.ch20.ex3;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class DateParser implements Parser {

	@Override
	public DateList parse(String data) {
		String[] numbers = data.split(",");

		DateList dateList = new DateList();

		dateList.setDates(new ArrayList<Date>());

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		for (String string : numbers) {
			try {
				Date date = sdf.parse(string);
				dateList.getDates().add(date);
			} catch (ParseException e) {
				e.printStackTrace();
			}
			
		}

		return dateList;
	}

}
